package com.gking.processHarvest.controller;


import com.gking.processHarvest.common.Res;
import com.gking.processHarvest.entity.Permissions;
import com.gking.processHarvest.entity.Role;
import com.gking.processHarvest.entity.RolePs;
import com.gking.processHarvest.entity.RoleUser;
import com.gking.processHarvest.service.Role.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;


    /**
     * 获取角色列表
     *
     * @return s
     */
    @GetMapping("/roleList")
    public Res<List<Role>> getRoleList() {
        return roleService.getRoleList();
    }


    /**
     * 获取权限列表
     *
     * @return s
     */
    @GetMapping("/permissionsList")
    public Res<List<Permissions>> getPermissionsList() {
        return roleService.getPermissionsList();
    }


    /**
     * 获取角色权限详情
     *
     * @param roleId 角色id
     * @return s
     */
    @GetMapping("/rolePermissionsDetail/{roleId}")
    public Res<List<RolePs>> getRolePermissionsDetail(@PathVariable String roleId) {
        return roleService.getRolePermissionsDetail(roleId);
    }


    /**
     * 为角色设置权限
     *
     * @param roleId          角色id
     * @param permissionsList 权限id 列表
     * @return s
     */
    @PostMapping("/setRolePermissions/{roleId}")
    public Res<String> setRolePermissions(@PathVariable String roleId, @RequestBody List<String> permissionsList) {
        return roleService.setRolePermissions(roleId, permissionsList);
    }


    /**
     * 获取用户角色详情
     *
     * @return s
     */
    @GetMapping("/getUserRoles")
    public Res<List<RoleUser>> getUserRolesDetail() {
        return roleService.getUserRolesDetail();
    }


    /**
     * 为用户设置角色(为登录用户)
     *
     * @param roleList 角色id 列表
     * @return s
     */
    @PostMapping("/setUserRoles")
    public Res<String> setUserRoles(@RequestBody List<String> roleList) {
        return roleService.setUserRoles(roleList);
    }


}
